"""
@Author    : ghenyar
@Time      : 2025/8/28 12:25
@File      : BaseEnum
@Desc      : 基础富枚举类
"""
import enum
from typing import Optional, List, Dict


class BaseStrEnum(str, enum.Enum):
    # 字符串型富枚举
    def __new__(cls, value, label):
        obj = str.__new__(cls, value)
        obj._value_ = value
        obj.label = label
        return obj

    @classmethod
    def get_label(cls, value) -> Optional[str]:
        try:
            return cls(value).label
        except ValueError:
            return None

    @classmethod
    def get_all_list(cls) -> List[Dict[str, str]]:
        return [
            {"label": item.label, "value": item.value}
            for item in cls
        ]

class BaseIntEnum(enum.IntEnum):
    # 整型富枚举
    def __new__(cls, value, label):
        obj = int.__new__(cls, value)
        obj._value_ = value
        obj.label = label
        return obj

    @classmethod
    def get_label(cls, value) -> Optional[str]:
        try:
            return cls(value).label
        except ValueError:
            return None

    @classmethod
    def get_all_list(cls) -> List[Dict[str, int]]:
        return [
            {"label": item.label, "value": item.value}
            for item in cls
        ]